package com.kukudexin.config;

import com.kukudexin.handle.TimeHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
/**
 * @author: 酷酷的鑫
 * @Date: 2021/10/9 17:16
 * @description:
 */
@Configuration
public class RouterConfig {
    @Autowired
    private TimeHandler timeHandler;
    @Bean
    public RouterFunction<ServerResponse> timerRouter() {
        // 这种方式相对于上一行更加简洁
        return route(GET("/time"), req -> timeHandler.getTime(req))
                .andRoute(GET("/date"), timeHandler::getDate)
                .andRoute(GET("/times"), timeHandler::sendTimePerSec);

    }
}
